//
//  BaseVC.swift
//  测试TextField
//
//  Created by shanlin on 2017/11/29.
//  Copyright © 2017年 shanlin. All rights reserved.
//

import UIKit

class BaseVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
        scrollView.keyboardDismissMode = .onDrag
        scrollView.backgroundColor = UIColor(white: 220/255, alpha: 1.0)
        self.view = scrollView
        setupUI()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        setupLayout()
    }

}

extension BaseVC {
    fileprivate func setupUI() {
        
    }
    
    fileprivate func setupLayout() {
        var lastMaxY: CGFloat = 20
        for view in self.view.subviews {
            view.frame.origin = CGPoint(x: 20, y: lastMaxY)
            lastMaxY = lastMaxY + view.frame.size.height + 20
        }
        
        if let contentView = self.view as? UIScrollView {
            contentView.contentSize.height = lastMaxY
        }
    }
}
